import { CopyInfoPanelBase } from "../CopyInfoPanelBase";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { DomWarPointCellRenderer } from "./DomWarPointCellRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { DomWarPointInfo } from "./DomWarPointInfo";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { Cache } from "../../../cache/Cache";
import { ClockManager } from "../../../manager/ClockManager";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { SDominionBossInfoList } from "../../../../../Message/Public/SDominionBossInfoList";
import { BossConfig } from "../../../resource/BossConfig";
import { SDominionRefreshBoss } from "../../../../../Message/Public/SDominionRefreshBoss";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class DominionWarCopyInfoPanel
    
    export  class DominionWarCopyInfoPanel extends CopyInfoPanelBase
    {
        constructor(arg1: string="MagicTowerInfoButtonBg")
        {
            super(arg1);
            this.title = Language.getString(90605);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._bg.alpha = 0.55;
            this._container = new Object /* flash.display.Sprite */();
            this._moveSp.addChild(this._container);
            this._container.y = 15;
            var loc1=GlobalStyle.textFormat1.clone();
            loc1.size = 14;
            var loc2=5;
            this._remText = Language.getString(40664) + Language.getString(53017);
            this._remainTimeTxt = ObjCreate.createGTextField(this._remText, loc2, 10, 200, 25, this._container, loc1);
            var loc3=this._remainTimeTxt.x + this._remainTimeTxt.textWidth + 1;
            this._rmTimeShowTxt = ObjCreate.createGTextField("00: 00", loc3, 10, 70, 25, this._container, loc1);
            this._warInfoBtn = ObjCreate.createGButton(Language.getString(90606), 201, 10, 70, 28, this._container);
            this._warInfoBtn.x = this._rmTimeShowTxt.x + this._rmTimeShowTxt.textWidth + 20;
            this._warInfoBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            ObjCreate.createBg(25, 45, 220, 2, this._container, ImagesConst.SplitLine);
            ObjCreate.createGTextField(Language.getString(90607) + ":", loc2, 50, 50, 25, this._container, loc1);
            this._mapPointList = new GTileList();
            this._mapPointList.columnCount = 3;
            this._mapPointList.rowCount = 2;
            this._mapPointList.columnWidth = 35;
            this._mapPointList.rowHeight = 35;
            this._mapPointList.horizontalGap = 30;
            this._mapPointList.verticalGap = 20;
            this._mapPointList.useFixed = true;
            this._mapPointList.setSize(160, 80);
            this._mapPointList.setStyle("cellRenderer", DomWarPointCellRenderer);
            this._mapPointList.setStyle("skin", new Object /* flash.display.Sprite */());
            this._mapPointList.move(loc2 + 30, 80);
            this._container.addChild(this._mapPointList);
            ObjCreate.createBg(25, 185, 220, 2, this._container, ImagesConst.SplitLine);
            return;
        }

        /* internal  */getDataProve(arg1: Boolean=false): DataProvider
        {
            var loc5=null;
            var loc7=null;
            var loc8=null;
            var loc1=new DataProvider();
            var loc2=Language.getString(90612);
            var loc3;
            var loc4=(loc3 = loc2.split(",")).length;
            var loc6=["46,225", "94,69", "134,110", "49,111", "93,265", "137,225"];
            var loc9=0;
            while (loc9 < loc4) 
            {
                loc5 = new DomWarPointInfo();
                if (loc9 < loc6.length) 
                {
                    loc8 = (loc7 = loc6[loc9]).split(",");
                    loc5.monsterPoint = new Object /* flash.geom.Point */(loc8[0], loc8[1]);
                }
                loc5.nameTxt = loc3[loc9];
                loc5.isBossRefresh = arg1;
                loc1.addItem(loc5);
                ++loc9;
            }
            return loc1;
        }

        protected onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.OnOpenDomWarRank));
            return;
        }

        /* internal  */startTimer(): void
        {
            if (!this._secTimer) 
            {
                this._secTimer = new SecTimer();
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerRun);
            }
            this._secTimer.reset();
            this._secTimer.start();
            return;
        }

        /* internal  */onTimerRun(arg1: SecTimer): void
        {
            this.updateUpt();
            return;
        }

        /* internal  */stopTimer(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
            }
            return;
        }

        /* internal  */updateUpt(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=NaN;
            if (Cache.instance.dominion.battleInfo) 
            {
                loc1 = ClockManager.instance.nowDate;
                loc2 = Cache.instance.dominion.battleInfo.endDate;
                loc3 = loc2.time - loc1.time;
                loc3 = loc3 / 1000;
                this._rmTimeShowTxt.text = RemainTimeTool.getRemainTimeBySeconds(loc3, false);
            }
            return;
        }

        public /* override */ updateInfos(arg1): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=0;
            var loc9=0;
            super.updateInfos(arg1);
            var loc1=[];
            if (arg1.msg && arg1.msg is SDominionBossInfoList) 
            {
                loc4 = (loc5 = arg1.msg as SDominionBossInfoList).bossInfos.length;
                loc8 = 0;
                while (loc8 < loc4) 
                {
                    loc6 = loc5.bossInfos[loc8];
                    (loc3 = new DomWarPointInfo()).monsterPoint = new Object /* flash.geom.Point */(loc6.point.x, loc6.point.y);
                    loc3.force = loc6.force;
                    if ((loc7 = BossConfig.instance.getInfoByCode(loc6.bossId).boss.name).length > 2) 
                    {
                        loc7 = loc7.substr(-3, 2);
                    }
                    loc3.nameTxt = loc7;
                    loc1.push(loc3);
                    ++loc8;
                }
                this._mapPointList.dataProvider = new DataProvider(loc1);
            }
            else if (arg1.msg && arg1.msg is SDominionRefreshBoss) 
            {
                loc1 = this._mapPointList.dataProvider.toArray();
                if ((loc4 = loc1.length) >= 6) 
                {
                    loc9 = 0;
                    while (loc9 < loc4) 
                    {
                        (loc3 = loc1[loc9]).isBossRefresh = true;
                        ++loc9;
                    }
                    this._mapPointList.dataProvider = new DataProvider(loc1);
                }
                else 
                {
                    this._mapPointList.dataProvider = this.getDataProve(true);
                }
            }
            else if (arg1.over) 
            {
                this._mapPointList.dataProvider = this.getDataProve();
            }
            return;
        }

        public /* override */ hidePanel(): void
        {
            super.hidePanel();
            this.stopTimer();
            return;
        }

        public /* override */ showPanel(): void
        {
            super.showPanel();
            this.startTimer();
            return;
        }

        public /* override */ updatePosition(): void
        {
            super.updatePosition();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.startTimer();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.stopTimer();
            return;
        }

        /* internal */ /* var */_line: ScaleBitmap;

        /* internal */ /* var */_remainTimeTxt: GTextFiled;

        /* internal */ /* var */_remText: string;

        /* internal */ /* var */_warInfoBtn: GButton;

        /* internal */ /* var */_container: Object /* flash.display.Sprite */;

        /* internal */ /* var */_rmTimeShowTxt: GTextFiled;

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_mapPointList: GTileList;
    }
